<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="../../../static/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../../static/js/jquery.js"></script>
<script type="text/javascript">
  //全局信息
  let pageSize = 5;
  var conn = {
    uid:null,
    purchaseId:null,
    prePurchaseTime:null,
    afterPurchaseTime:null,
    preTotalMoney:null,
    afterTotalMoney:null,
    checkStatus:2
  };

  function getParameterCPE() {
    let user = JSON.parse(localStorage.getItem("user"));
    conn = {
      uid:user.uid,
      purchaseId:$("#cpel_Id").val(),
      prePurchaseTime:$("#cpel_PreTime").val(),
      afterPurchaseTime:$("#cpel_AfterTime").val(),
      preTotalMoney:$("#cpel_PreMon").val(),
      afterTotalMoney:$("#cpel_AfterMon").val(),
      checkStatus:2
    };
  }


  function searchCPE(){
    getParameterCPE();
    queryPurchaseExamine(1);
  }

  $(function () {
    getParameterCPE();
    queryPurchaseExamine(1);
  })

  function queryPurchaseExamine(currentPage) {
    conn.pageNum = currentPage;
    conn.pageSize = pageSize;
    $.ajax({
      url:"/purchase/queryPurchasePage",
      method:"post",
      data:conn,
      dataType:"JSON",
      success:function (rel) {
        console.log(conn);
        let str = '';
        rel.data.data.forEach(function (purchase,i) {
          //对审核状态做处理
          let checkStatusName;
          if (purchase.checkStatus === "1"){
            checkStatusName = "未审核";
          }else if (purchase.checkStatus === "2"){
            checkStatusName = "审核中";
          }else if (purchase.checkStatus === "3"){
            checkStatusName = "审核通过";
          }else {
            checkStatusName = "审核未通过";
          }
          //数据显示
          str +=
                  '<tr>\n' +
                  '          <td>'+((++i)+(currentPage-1)*pageSize)+'</td>\n' +
                  '          <td>'+purchase.purchaseId+'</td>\n' +
                  '          <td>'+purchase.purchaseTime+'</td>\n' +
                  '          <td>'+purchase.totalMoney+'</td>\n' +
                  '          <td>'+purchase.creatName+'</td>\n' +
                  '          <td>'+checkStatusName+'</td>\n';
          str += '<td>\n' +
                  '            <a href="examine?purchaseId='+purchase.purchaseId+'" class="tablelink">审核</a>\n' +
                  '          </td>\n' +
                  '        </tr>';
        })
        $("#cpel_tbody").html(str);
        //分页显示
        let strbu = '<div class="message">共<i class="blue">'+rel.data.totalCount+'</i>条记录，当前显示第<i class="blue">'+currentPage+'</i>页</div>';
        let beforeNum;
        if (currentPage>1){
          beforeNum = currentPage -1;
        }else {
          beforeNum = 1;
        }
        strbu +='<ul class="paginList">\n' +
                '   <li class="paginItem"><a href="javascript:;" onclick="queryPurchaseExamine('+beforeNum+')"><span class="pagepre"></span></a></li>';

        //定义开始位置begin和结束位置end
        var begin;
        var end;
        if (rel.data.totalPage<5){
          //总页码不够5页
          begin = 1;
          end = rel.data.totalPage;
        }else {
          //总页码超过5页
          begin = rel.data.pageNum - 1;
          end = rel.data.pageNum + 3;
          if (begin<=1){
            begin = 1;
            end = begin + 4;
          }
          if (end >= rel.data.totalPage){
            end = rel.data.totalPage;
            begin = end - 4;
          }
        }

        for (let i = begin; i <= end; i++) {
          let li = '';
          if (i===rel.data.pageNum){
            li='<li class="paginItem current"><a href="javascript:;" onclick="queryPurchaseExamine('+currentPage+')">'+currentPage+'</a></li>';
          }else {
            li='<li class="paginItem"><a href="javascript:;" onclick="queryPurchaseExamine('+i+')">'+i+'</a></li>';
          }
          strbu += li;
        }

        let nextNum;
        if (currentPage>=rel.data.totalPage){
          nextNum = rel.data.totalPage;
        }else {
          nextNum = currentPage+1;
        }
        strbu += '        <li class="paginItem"><a href="javascript:;" onclick="queryPurchaseExamine('+nextNum+')"><span class="pagenxt"></span></a></li>';
        $("#cpel_page").html(strbu);
      }
    })
  }
</script>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>采购单审核</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post">
    <ul class="tools">
      <li> 采购单编号:
        <input type="text" id="cpel_Id" />
      </li>
      <li> 采购时间:
        <input id="cpel_PreTime" type="date" />-<input id="cpel_AfterTime" type="date" />
      </li>
      <li> 金额:
        <input id = cpel_PreMon type="text" class="stinput" />-<input type="text" id="cpel_AfterMon" class="stinput" />
      </li>
      <li class="subBut" onclick="searchCPE()">
      <img src="../../../static/images/t06.png"  />查询
      </li>
    </ul>
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>采购单编号</th>
          <th>采购时间</th>
          <th>金额</th>
          <th>操作人</th>
          <th>审核状态</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody id="cpel_tbody">
        <tr>
          <td>1</td>
          <td>DJ201701270001</td>
          <td>2017-01-25 15:05:05</td>
          <td>￥9,876,582</td>
          <td>关羽</td>
          <td>审核中</td>
          <td>
            <a href="purchaseExamine.html" class="tablelink">审核</a>
          </td>
        </tr>
        <tr>
          <td>2</td>
          <td>DJ201701270002</td>
          <td>2017-01-25 15:05:05</td>
          <td>￥9,876,582</td>
          <td>关羽</td>
          <td>审核中</td>
          <td>
            <a href="purchaseExamine.html" class="tablelink">审核</a>
          </td>
        </tr>
      </tbody>
    </table>
    <div class="pagin" id="cpel_page">
      <div class="message">共<i class="blue">1256</i>条记录，当前显示第&nbsp;<i class="blue">2&nbsp;</i>页</div>
      <ul class="paginList">
        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>
        <li class="paginItem"><a href="javascript:;">1</a></li>
        <li class="paginItem current"><a href="javascript:;">2</a></li>
        <li class="paginItem"><a href="javascript:;">3</a></li>
        <li class="paginItem"><a href="javascript:;">4</a></li>
        <li class="paginItem"><a href="javascript:;">5</a></li>
        <li class="paginItem more"><a href="javascript:;">...</a></li>
        <li class="paginItem"><a href="javascript:;">10</a></li>
        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>
      </ul>
    </div>
  </form>
</div>
<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
